package com.milestone.fitnesspersonaltrainer.network.encrypt;

import com.google.gson.TypeAdapter;

import java.io.IOException;

import okhttp3.ResponseBody;
import retrofit2.Converter;

/**
 * Created by ThinkPad on 2018/2/28.
 * 自定义响应ResponseBody
 */
public class JsonResponseBodyConverter<T> implements Converter<ResponseBody, T> {
    private final TypeAdapter<T> adapter;
    JsonResponseBodyConverter(TypeAdapter<T> adapter) {
        this.adapter = adapter;
    }
    @Override
    public T convert(ResponseBody value) throws IOException {
        String json = value.string();
//        try {
//            json = new String(new AesEncryptionUtil().decrypt(value.string()));
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
        System.out.println("-------------------Json : " + json);
        return adapter.fromJson(json);
    }
}